home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 February (DVD) / PCWorld_2008-02_DVD.iso / v cisle / PHP / PHP.exe / EasyPHP-2.0b1-setup.exe / {app} / sqlitemanager / include / config.inc.php < prev    next >
Encoding:
PHP Script  |  2006-04-18  |  4.3 KB  |  143 lines

  1. <?php
  2. /**
  3. * Web based SQLite management
  4. * Check if the config database is OK
  5. * and set a tab with the list of user's databases
  6. * @package SQLiteManager
  7. * @author FrΘdΘric HENNINOT
  8. * @version $Id: config.inc.php,v 1.28 2006/04/18 06:43:20 freddy78 Exp $ $Revision: 1.28 $
  9. */
  10.  
  11. include_once INCLUDE_LIB."grab_global.php";
  12. include_once INCLUDE_LIB."SQLite.i18n.php";
  13. include_once INCLUDE_LIB."SQLiteAutoConnect.class.php";
  14. include_once INCLUDE_LIB."common.lib.php";
  15.  
  16. $SQLiteFactory = new SQLiteAutoConnect();
  17.  
  18. function LastAction() {
  19.   global $workDb, $db;
  20.   if(isset($workDb))
  21.    if ($workDb->connId && ($workDb->baseName!=":memory:")) {
  22.            if($workDb->connId->dbVersion == 2) $workDb->close();
  23.         else $workDb = null;
  24.         if($db->dbVersion == 2) $db->close();
  25.         else $db = null;
  26.   }
  27. }
  28. register_shutdown_function('LastAction');
  29. if(isset($noframe)){
  30.     session_register("noframe");
  31.     $_SESSION["noframe"] = $noframe = true;
  32. }
  33.  
  34. if(!file_exists("./theme/".$localtheme."/define.php")) {
  35.     unset($_COOKIE["SQLiteManager_currentTheme"]);
  36.     $localtheme = "default";
  37. }
  38. include_once("./theme/".$localtheme."/define.php");
  39.  
  40. if(!CheckExtension('sqlite') && !(CheckExtension('pdo') && CheckExtension('pdo_sqlite'))){
  41.     displayError($traduct->get(6));
  42.     exit;    
  43. } else {
  44.     // Search SQLite versions (if available version2 and version3)
  45.     $tabSQLiteVersion = array();
  46.     if(function_exists('sqlite_open')) {
  47.         $tabSQLiteVersion[] = sqlite_libversion();
  48.     }
  49.     if(class_exists('PDO') && in_array('sqlite', PDO::getavailabledrivers())) {
  50.         $dbVersion = new PDO('sqlite::memory:', '', '');
  51.         $query = "SELECT sqlite_version();";
  52.         $res = $dbVersion->query($query);
  53.         $tabSQLiteVersion[] = $res->fetchColumn();    
  54.         unset($dbVersion);     
  55.     }
  56.     $SQLiteVersion = implode(' - ', $tabSQLiteVersion);
  57.     $sqliteVersionAvailable = array();
  58.     foreach($tabSQLiteVersion as $versionAvailable) {
  59.         $sqliteVersionAvailable[] = substr($versionAvailable, 0, 1);
  60.     }
  61.     if(!defined('SQLiteDb')) {
  62.         if(isset($sqliteVersionAvailable)) {
  63.             define ("SQLiteDb", dirname(__FILE__) . "/config".(($sqliteVersionAvailable[0] == 2)? '' : $sqliteVersionAvailable[0] ).".db");
  64.         } else {
  65.             define("SQLiteDb", dirname(__FILE__) . "/config.db");
  66.         }
  67.     }
  68.     
  69.     $tempError = error_reporting();
  70.     error_reporting(E_ALL & ~(E_ERROR | E_WARNING | E_PARSE | E_NOTICE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING | E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE));
  71.  
  72.     $db = $SQLiteFactory->sqliteGetInstance(SQLiteDb);
  73.     
  74.     if(!$db){
  75.         displayError($traduct->get(7)." : $error");
  76.         exit;
  77.     }
  78.  
  79.     define("READ_ONLY", !is_writeable(SQLiteDb));
  80.     /*
  81.     if(!is_writeable(SQLiteDb)){    
  82.         displayError($traduct->get(8));
  83.         exit;
  84.     }
  85.     */
  86.     
  87.     error_reporting($tempError);
  88.     
  89.     if(WITH_AUTH){
  90.         include_once INCLUDE_LIB."SQLiteAuth.class.php";
  91.         $SQLiteManagerAuth =& new SQLiteAuth();
  92.     }
  93.  
  94.     $query = "SELECT count(*) FROM database";
  95.     if($db->query($query)){
  96.             if(!$db->fetch_array()){
  97.                 displayHeader("");
  98.                 $noDb = true;
  99.                 include_once INCLUDE_LIB."add_database.php";
  100.                 if(empty($action) || $error) exit;
  101.             }
  102.     }
  103.  
  104.     // check if exist ':memory: database
  105.     $query = "SELECT * FROM database WHERE location LIKE ':memory:'";
  106.     if($db->query($query)){
  107.         $tempMem = $SQLiteFactory->sqliteGetInstance(':memory:');
  108.     }
  109.     $tabDb = $db->array_query($query, SQLITE_ASSOC);
  110.     
  111.     if($dbsel){
  112.         $tabInfoDb = $db->array_query("SELECT * FROM database WHERE id=$dbsel", SQLITE_ASSOC);
  113.         $tabInfoDb = isset($tabInfoDb[0])?$tabInfoDb[0]:'';
  114.     }
  115.     
  116.     $query = "SELECT name FROM sqlite_master WHERE type='table' AND name='attachment';";
  117.     $existAttachTable = $db->array_query($query, SQLITE_ASSOC);
  118.     if(empty($existAttachTable)) {
  119.         // create table for attachment management
  120.         $query = "CREATE TABLE attachment (
  121.                     id INTEGER PRIMARY KEY ,
  122.                     base_id INTEGER ,
  123.                     attach_id INTEGER) ;";
  124.         $db->query($query);
  125.     }
  126.     $attachDbList = array();
  127.     $attachLocation = array();
  128.     if(!empty($dbsel)){
  129.         // Get attach database list for dbsel
  130.         $query = "SELECT attach_id, location, name FROM attachment LEFT JOIN database ON database.id=attachment.attach_id WHERE base_id=".$dbsel;
  131.         $attachList = $db->array_query($query, SQLITE_ASSOC);
  132.         $attachDbList = array();
  133.         $attachInfo = array();
  134.         foreach($attachList as $key=>$value) {
  135.             $attachDbList[] = $value["attach_id"];    
  136.             $attachInfo[$value["attach_id"]]["location"] = $value["location"];
  137.             $attachInfo[$value["attach_id"]]["name"] = $value["name"];
  138.         }    
  139.     }        
  140. }
  141.  
  142. ?>
  143.